﻿using OddUserManager.Data.Repositories;
using OddUserManager.Model;
using OddUserManager.Service.IServices;
using OddUserManager.Service.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;

namespace OddUserManager.Web.Common
{
    public static class CacheData
    {
        static Timer time = new Timer();
        static IOddService _service = new OddService(new OddRepository());
        //static IReportService _reportService = new ReportService(new ReportRepository());
        public static List<Odd> AllOdds = new List<Odd>();

        public static List<JCMatchOddDistributionGraph> AllJCMatchOddDistributionGraph = new List<JCMatchOddDistributionGraph>();

        static CacheData()
        {
            AllOdds = _service.GetAllList();
           
            time.Interval = 300000;
            time.Elapsed += Time_Elapsed;
            time.Start();
        }

        private static void Time_Elapsed(object sender, ElapsedEventArgs e)
        {
            AllOdds = _service.GetAllList();
            //AllJCMatchOddDistributionGraph = _reportService.GetAllJCMatchOddDistributionGraph();
        }
    }

    public static class RedBlackDataCache
    {
        static Timer time = new Timer();
        static IOddUserService _service = new OddUserService(new OddUserRepository());
        //static IReportService _reportService = new ReportService(new ReportRepository());
        public static List<OddUser> Data = new List<OddUser>();

      

        static RedBlackDataCache()
        {
            Data = _service.GetAllUsersWithOdds(10);
            time.Interval = 30000;
            time.Elapsed += Time_Elapsed;
            time.Start();
        }

        private static void Time_Elapsed(object sender, ElapsedEventArgs e)
        {
            Data = _service.GetAllUsersWithOdds(10);
        }
    }

    //public  class JCMatchData {

    //    private static JCMatchData _instance = null;

    //    private static object _lock = new object();

    //    private JCMatchData() { }

    //    public static JCMatchData GetInstance() {
    //        if (null == _instance)
    //        {
    //            lock (_lock)
    //            {
    //                _instance = new JCMatchData();
    //            }
    //        }
    //        return _instance;
    //    }


    //    public void InsertNewMacthNumbers(List<string> list)
    //    {
    //        lock (_lock)
    //        {
    //            NewMatchNumbers.AddRange(list);
    //        }
    //    }


    //    public List<string> GetNewMacthNumbers() {
    //        List<string> list = new List<string>();
    //        if (list.Count > 0)
    //        {
    //            lock (_lock)
    //            {
    //                list = NewMatchNumbers;
    //                NewMatchNumbers = new List<string>();
    //            }
    //        }

    //        return list;
    //    }


    //    public DateTime? CurrentMaxTime { get; set; }

    //    private List<string> NewMatchNumbers = new List<string>();
    //}


}
